﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Wolfbyte.Core.InversionOfControl
{
    public static class IoC
    {
        private static bool _initialized = false;
        private static object initializationLock = new object();
        private static IContainer _container;

        public static void Initialize(IContainer container)
        {
            if (_initialized == false)
            {
                lock (initializationLock)
                {
                    if (_initialized == false)
                    {
                        _container = container;
                        _initialized = true;
                    }
                }
            }
            else
            {
                throw new InvalidOperationException("IoC already initialized");
            }
        }

        public static IContainer Container
        {
            get
            {
                if (_initialized == false)
                    throw new InvalidOperationException("IoC not initialized");
                return _container;
            }
        }

        public static T Resolve<T>()
        {
            return Container.Resolve<T>();
        }

        public static T Resolve<T>(string key)
        {
            return Container.Resolve<T>(key);
        }
    }
}
